
<template>
  <div class="main">
    <top-bar></top-bar>
    <div class="main-mains w90">
      <div class="main-mains-l">
        <router-link to="/main">
          <div class="main-mains-l-return">
            <span>←</span>
            返回首页
          </div>
        </router-link>
        <div class="active">便民电话</div>
        <router-link to="/living">
          <div>发布生活区信息</div>
        </router-link>
        <router-link to="/propertylist">
          <div>已发布生活区信息</div>
        </router-link>
      </div>
      <div class="main-mains-r">
        <div class="ueditor-txt">
          <el-input v-model="title" class="txt-title" maxlength = '30'   placeholder="请输入标题"></el-input>
          <!-- 加载编辑器的容器 -->
          <script id="content" name="content" type="text/plain">
            这里写你的初始化内容
          </script>
          <div class="txt-btn" @click="addNews()">
            发布
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import topBar from "../public/top";
export default {
  components: {
    topBar
  },
  data() {
    return {
      title: "",
      id: this.$route.params.id,
      time: new Date().toLocaleDateString()
    };
  },
  methods: {
    getNewDetails() {
      let _this = this;
      let datas = {
        id: _this.id
      };
      datas = JSON.stringify(datas);
      _this
        .$http({
          url: _this.urls + "/propertyInfo/findById.do",
          method: "post",
          data: datas
        })
        .then(function(res) {
          let data = res.data;
          if (data.status == "success") {
            _this.title = data.data.title;
            let instructionsue = UE.getEditor("content");
            instructionsue.ready(function() {
              instructionsue.setContent(data.data.context);
            });
          } else {
            _this.$message({
              showClose: true,
              message: data.msg,
              type: "error"
            });
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    addNews() {
      let _this = this;
      if (_this.title == "") {
        this.$message.error("请输入文章标题");
        return false;
      }
      let _content = UE.getEditor("content").getContent();
      let datas = {
        context: _content,
        title: _this.title,
        id: _this.id,
        createtime: _this.time
      };
      datas = JSON.stringify(datas);
      _this
        .$http({
          url: _this.urls + "/propertyInfo/update",
          method: "post",
          data: datas
        })
        .then(function(res) {
          let data = res.data;
          if (data.status == "success") {
            _this.$message({
              showClose: true,
              message: "编辑成功！",
              type: "success"
            });
            _this.title = '';
          } else {
            _this.$message({
              showClose: true,
              message: data.msg,
              type: "error"
            });
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    }
  },
  mounted() {
    this.getNewDetails();
    UE.getEditor("content", {
      initialFrameWidth: 682,
      initialFrameHeight: 400,
      autoHeightEnabled: false,
      zIndex: 0
    });
  },
  destroyed() {
    UE.delEditor("content");
  }
};
</script>

<style lang="less" scoped>
@import "property.less";
</style>



